﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.LunarSocket;
using ServerBase.Protocol;
using UtilLib;
using static ServerBase.Config.Conf;
using static ServerBase.Service.BaseDispatch;
using static UtilPublic.Redis.ServerRedis;
using ServerGame.Service;
using System.Collections.Generic;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using ServerBase.Config;
using static ServerGame.Service.Dispatcher;
using ServerBase.Client;
using System;
using ServerPublic.Data;
using ServerGame.GameObject;
using static UtilPublic.Serialization.Jsh;
using ServerPublic.DataBaseMysql;
using UtilPublic.ApiDispatcher;
using ServerGame.Data;
using static ServerGame.Manager.Efun;
using System.Linq;

namespace ServerGame.Manager
{
    public partial class DispatcherMsg
    {
        [ApiDpPro((short)EProtocolId.C2G_NPC_LOOK, "查看")]
        public short OnNpcLook()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnNpcLook();

            Rsp.Uid = Req.Uid;
            if (!player.Room.DictNpc.TryGetValue(Req.Uid, out var ppp))
            {
                Rsp.MessageFail("你要看什么？"); return Send(Rsp);
            }
            Send(Rsp);

            var pro = GenderPronoun(ppp.Cfg.Gender);
            player.Message(ppp.Desc);
            if (ppp.Cfg.Age < 10)
            {
                player.Message($"{pro}看起来显然还不到十岁。");
            }
            else
            {
                player.Message($"{pro}看起来约{ChineseNumber(ppp.Cfg.Age / 10 * 10)}多岁。");
            }
            if (ppp.Level > player.Level * 3)
            {
                player.Message($"{pro}的修为看起来似乎#HIW#无法估量#NOR#。");
            }
            else
            {
                player.Message($"的修为看起来{DescLevel(ppp.Level)}。");
                player.Message($"出手似乎{DescDamage(ppp[EProp.damage])}。");
            }
            player.Message($"{pro}{DescKee(ppp[EProp.kee], ppp[EProp.mxkee])}");

            var descper = DescPer(ppp.Cfg.Age, ppp.Cfg.Gender, ppp[EProp.per] + ppp[EProp.adper]);
            player.Message($"{pro}{descper}");

            return 0;
        }
        [ApiDpPro((short)EProtocolId.C2G_NPC_KILL, "攻击")]
        public short OnNpcKill()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnNpcKill();

            Rsp.Uid = Req.Uid;
            if (player.IsBusy)
            {
                Rsp.MessageFail("你现在正忙着呢，没空去杀人。"); return Send(Rsp);
            }
            if (player.Room.NoFight)
            {
                Rsp.MessageFail("这里不能战斗哦。"); return Send(Rsp);
            }
            if (!player.Room.DictNpc.TryGetValue(Req.Uid, out var ppp))
            {
                Rsp.MessageFail("这里没有这个人。"); return Send(Rsp);
            }
            if (!ppp.Cfg.CanFight)
            {
                Rsp.MessageFail($"你想对{ppp.MudName()}下杀手，但是看着{GenderPronoun(ppp.MudGender())}那呆若木鸡的样子，你始终狠不下心来。"); return Send(Rsp);
            }
            string callname = ppp.MudRude();
            if (Util.RandBool())
            {
                MessageVision("#HIR#$N对着$n喝道：「" + callname + "！今日不是你死就是我活！」", player, ppp);
            }
            else
            {
                MessageVision("#HIR#$N对着$n喝道：「" + callname + "！！明年今日就是你的忌日！」", player, ppp);
            }
            player.IsFighting = true;
            player.EnemyAdd(ppp);

            ppp.IsFighting = true;
            ppp.EnemyAdd(player);

            return Send(Rsp);
        }

    }
}
